package com.bjxst;

import java.io.*;

/** 通过字节流读取文本文件并添加行号*/
public class LineNumber02 {
    public static void main(String[] args) {
        BufferedReader br = null;
        BufferedWriter bw = null;
        try{
            br = new BufferedReader(new InputStreamReader(new FileInputStream("d:/b.txt")));
            bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("d:/e.txt")));
            String temp = "";
            int i = 1;
            while ((temp= br.readLine()) != null ){
                bw.write(i+","+temp);
                bw.newLine();//换行
                i++;
            }
            bw.flush();
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            try{
                if(br != null){
                    br.close();
                }
                if(bw != null){
                    bw.close();
                }
            }catch (Exception e){
                e.printStackTrace();
            }
        }
    }
}
